package com.myweb.demo.repository;

import com.myweb.demo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface UserRepository extends JpaRepository<User,Long> {
    @Override
    List<User> findAll();

    @Override
    Optional<User> findById(Long aLong);

    @Query("select u from User u where u.userId = ?1")
    User getUserByUserId(Long id);

    @Override
    <S extends User> S saveAndFlush(S s);

    @Query("select u from User u where u.userName=?1 and u.userPassword=?2")
    User getUserByUserNameAndUserPassword(String username,String password);
//    @Query("select count(userId) from user")
//    Long getNum();
    @Query("update User u set u.userName=?1, u.userSex=?2, u.userPassword=?3, u.qq=?4, u.userEmail=?5, u.imageAddr=?6 where u.userId=?7")
    void updateUser(String name,String sex,String password,String qq,String email,String imgAddr,Long id);


}

